package com.huopaolan.yohuoshop.Dao.Utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.Nullable;

public class DBUtils extends SQLiteOpenHelper {

    public DBUtils(@Nullable Context context) {
        super(context, "userModules.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table User(user_id vachar(5),nick_name vachar(20),user_name vachar(20)," +
                "user_pwd vachar(20),user_sex vachar(5)," +
                "user_birthday vachar(20),user_height vachar(10)," +
                "user_weight vachar(10),user_head vachar(20))");
        db.execSQL("create table Shop(userid vachar(5),goodsid vachar(5)" +
                ",car_path vachar(10),shop_name vachar(15),shop_color vachar(15)" +
                ",shop_size vachar(10),shop_num vachar(10),shop_price vachar(20))");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    //添加用户
    public long insert(String userName, ContentValues values) {
        return getWritableDatabase().insert(userName, null, values);
    }

    //删除用户
    public int delete(String userName, String whereClause, String[] whereArgs) {
        return getWritableDatabase().delete(userName, whereClause, whereArgs);
    }

    //修改用户
    public int update(String userName, ContentValues values, String whereClause, String[] whereArgs) {
        return getWritableDatabase().update(userName, values, whereClause, whereArgs);
    }

    //查询用户
    public Cursor query(String userName, String whereClause, String[] whereArgs) {
        return getWritableDatabase().query(userName, null, whereClause, whereArgs, null, null, null);
    }
}
